<template>
  <div id="" style="height: 100%">
    <van-sticky class="search">
      <div class="searchItem">
        <van-row gutter="12">
          <van-col :span="24">
            <van-field
              v-model="searchFilter.title"
              placeholder="请输入标题"
              right-icon="search"
              @click-right-icon="handleQuery()"
            />
          </van-col>
        </van-row>
      </div>
    </van-sticky>
    <div class="content">
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
          :offset="10"
        >
          <van-cell
            v-for="(item, index) in dataList"
            :key="index"
            class="dateItem"
            @click="handleDetail(item)"
            clickable
          >
            <div class="card">
              <van-row gutter="20">
                <van-col :span="5">
                  <div
                    class="infoImg"
                    :style="{
                      background: 'url(' + setPreviewUrl(item) + ')',
                      backgroundSize: 'cover',
                      backgroundPosition: 'center',
                    }"
                  ></div>
                  <!-- <img :src="setPreviewUrl(item)" alt="" class="infoImg"> -->
                </van-col>
                <van-col :span="19">
                  <p class="textEllipsis">{{ item.title }}</p>
                  <p class="textEllipsis">{{ item.infoItemStr }}</p>
                  <p class="textEllipsis">发布时间：{{ item.publishTime }}</p>
                </van-col>
              </van-row>
            </div>
          </van-cell>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>
<script>
export default {
  name: "",
  data() {
    return {
      queryParams: {
        pageNum: 0,
        pageSize: 10,
      },
      searchFilter: {},
      dataList: [],
      loading: false,
      finished: false,
      refreshing: false,
    };
  },
  methods: {
    handleQuery() {
      this.onRefresh();
    },
    onRefresh() {
      this.dataList = [];
      this.queryParams.pageNum = 0;
      this.finished = false;
      this.onLoad();
    },
    onLoad() {
      let me = this;
      me.loading = true;
      me.queryParams.pageNum++;
      me.getInfo();
    },
    getInfo() {
      let me = this;
      if (me.$route.query.id) {
        me.searchFilter.groundId = me.$route.query.id;
      }
      me.$api
        .getInfoList({
          pageParam: me.queryParams,
          condition: me.searchFilter,
        })
        .then((res) => {
          if (res.dataList.length == 0) {
            // 本次没有数据
            me.dataList = [];
            //me.$toast('暂无数据');
            me.refreshing = false;
            me.finished = true;
          } else {
            // 本次有数据
            me.dataList = [...me.dataList, ...res.dataList];
            me.loading = false;
            me.refreshing = false;
            me.dataList.length >= res.totalCount ? (me.finished = true) : "";
          }
        });
    },
    setPreviewUrl(val) {
      if (val.coverImage && val.coverImage.length > 0) {
        return (
          process.env.VUE_APP_BASE_URL +
          "admin/upms/file/download?filename=" +
          val.coverImage[0]
        );
      } else {
        return "";
      }
    },
    handleDetail(item) {
      this.$router.push({
        path: "/info/detail",
        query: {
          id: item.infoId,
        },
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.mapHeight {
  width: 100%;
  height: 100%;
  .map {
    width: 100%;
    height: 100%;
  }
}

.typeImg {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
}
.content {
  padding: 0.2rem;
  background-color: #f5f5f5;
  height: calc(100vh - 3rem);
  overflow-y: scroll;
}
.groundImg {
  display: inline-block;
  width: 100%;
  height: 3.5rem;
}
</style>
